﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace DTC
{
    public partial class FrmSetting : UIBase
    {
        public FrmSetting()
        {
            InitializeComponent();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void FrmSetting_Load(object sender, EventArgs e)
        {
            this.edtCCDFile.Text = ConfigurationManager.AppSettings["ccdPath"];
            this.edtAtrFile.Text = ConfigurationManager.AppSettings["AtrPath"];
            this.edtBinComp.Text = ConfigurationManager.AppSettings["LGPath"];
            this.cboAtrCom.Text = ConfigurationManager.AppSettings["AtrCom"];
            this.cboIORun.Text = ConfigurationManager.AppSettings["IORunning"];
            this.cboReadOK.Text = ConfigurationManager.AppSettings["IOReadOK"];
            this.cboReady.Text = ConfigurationManager.AppSettings["IOAllTestOK"];
            this.cboStopIO.Text = ConfigurationManager.AppSettings["IOStopping"];
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection cfa = configuration.AppSettings;
            cfa.Settings["ccdPath"].Value = this.edtCCDFile.Text;
            cfa.Settings["AtrPath"].Value = this.edtAtrFile.Text;
            cfa.Settings["LGPath"].Value = this.edtBinComp.Text;
            cfa.Settings["AtrCom"].Value = this.cboAtrCom.Text;
            cfa.Settings["IORunning"].Value = this.cboIORun.Text;
            cfa.Settings["IOReadOK"].Value = this.cboReadOK.Text;
            cfa.Settings["IOAllTestOK"].Value = this.cboReady.Text;
            cfa.Settings["IOStopping"].Value = this.cboStopIO.Text;
            configuration.Save();
            ConfigurationManager.RefreshSection("AppSettings");
            this.Close();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectFilePath(this.edtAtrFile);
        }

        private void SelectFilePath(TextBox edt)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "请选择文件路径";
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                string folderPath = fbd.SelectedPath;
                edt.Text = folderPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SelectFilePath(this.edtCCDFile);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SelectFilePath(this.edtBinComp);
        }

    }
}
